import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    lastmusic:null,
    nextmusic:null,
    songid:null,
    curtime:null,
    paused:false,
    duration:null,
    ccur:null,
    songlist:null,
    playlist:null,
    way:1,
    lovelist:[],
    historylist:[],
  },
  getters: {
    randomlist(state){
      return state.playlist.sort(()=>{
        return Math.random()-0.5
      })
    },
    circlelist(state){
      return state.playlist.filter((item)=>{
              return item.id==state.songid
      })
    }
  },
  mutations: {
    // 更新当前播放时长
    changeCur(state,curtime){

      state.curtime=curtime
      
    },
    //更改歌曲播放状态
    changepaused(state,ispause){
        state.paused=ispause
    },
    // 更新歌曲总时长
    changeduration(state,duration){
      state.duration=duration
    },
    changeccur(state,ccur){
      state.ccur=ccur
    }
    ,
    // 更改当前播放歌曲
    changesongid(state,songid){
      state.songid=songid
    },
    // 播放列表
    changeplaylist(state,list){
      state.playlist=list
    },
    changesonglist(state,list){

         state.songlist=list

    },
    // 播放模式
    changeway(state){

         state.way++
    },
    // 添加喜欢
    addlove(state,id){
      // state.lovelist=[...new Set(state.lovelist)]

       state.lovelist.unshift({'id':id});
    },
    // 删除我的喜欢
    deletelove(state,id){
      // state.lovelist=[...new Set( state.lovelist)


      state.lovelist=state.lovelist.filter(item=>{

        item.id!==id

      })
    },
    addhistory(state,id){
      // state.lovelist=[...new Set(state.lovelist)]
       state.historylist.unshift({id:id});
    },
  
    
  },
  actions: {

    
  },
  modules: {
  }
})
